package com.frxuexi.park2212.merchant

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.base.BaseActivity
import com.frxuexi.park2212.R
import com.frxuexi.park2212.databinding.ActivityMerchantBinding
import com.frxuexi.park2212.databinding.ActivityMerchantDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/MerchantDetailActivity")
@AndroidEntryPoint
class MerchantDetailActivity : BaseActivity<ActivityMerchantDetailBinding,MerchantViewModel>() {
    @Autowired
    lateinit var mid:String
    override fun initData() {
        vm.getMerchantById.observe(this){
            binding.bean=it

            if(it.status=="新建"){
                binding.merdetailGroup.visibility=View.VISIBLE
                binding.merStatus.apply {
                    setText("处理中")
                }
                binding.merShenhe.setText("待处理")
            }else if(it.status=="驳回"){
                binding.merdetailGroup.visibility=View.GONE
                binding.merStatus.apply {
                    setText(it.status)
                    setBackgroundResource(R.drawable.shape_weihu)
                    setTextColor(resources.getColor(R.color.orange))
                }
                binding.merProCircle2.setBackgroundResource(R.drawable.shape_solid_orange)
                binding.merShenhe.setText(it.status)
                binding.merShTime.setText(it.processingSteps.get(1).stepTime)

            }else{
                binding.merdetailGroup.visibility=View.GONE
                binding.merStatus.apply {
                    setText(it.status)
                }
                binding.merProCircle2.setBackgroundResource(R.drawable.shape_solid_darkgreen)
                binding.merShenhe.setText(it.status)
                binding.merShTime.setText(it.processingSteps.get(1).stepTime)
            }
        }

        vm.approve.observe(this){
            ToastUtils.showLong("审核成功")
            finish()
        }
    }



    override fun initView() {
        ARouter.getInstance().inject(this)
        vm.getMerchantById(mid.toInt())

        binding.merappOk.setOnClickListener {
            vm.approve(mid.toInt())
        }

        binding.merappRefause.setOnClickListener {
            vm.reject(mid.toInt())
        }
    }

}